package com.xoa.dao.workflow;

import com.xoa.dao.base.BaseMapper;
import com.xoa.model.workflow.FlowDetailInfo;
import com.xoa.model.workflow.FlowTypeModel;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

public interface FlowTypeModelMapper extends BaseMapper<FlowTypeModel> {

    List<FlowTypeModel> selectBySortid(@Param("flowId") Integer flowId); 


    List<FlowTypeModel> selectBySearch(@Param("searchValue") String searchValue, @Param("sortId") Integer sortId);

    List<FlowTypeModel> selectFlowAuthOrSearch(Map<String, Object> map);
    List<FlowTypeModel> selectFlowAuthOrSearchAdmin(Map<String, Object> map);

    FlowDetailInfo selectFlowDetailInfo(@Param("flowId") Integer flowId);

    /**
     * 创建作者:   张勇
     * 创建日期:   2017/6/22 10:53
     * 方法介绍:   根据flowId 和 formId 查询一条数据
     * 参数说明:
     *
     * @return
     */
    public FlowTypeModel selectOnlyType(@Param("flowId") Integer flowId, @Param("formId") Integer formId);

    public FlowTypeModel queryOneObject(@Param("flowId") Integer flowId);

    /**
     * 创建作者:   张勇
     * 创建日期:   2017/7/7 10:44
     * 方法介绍:   查询说明和附件
     * 参数说明:   流程ID和表单ID
     *
     * @return
     */
    public FlowTypeModel selectAttachmentAndInstructions(@Param("flowId") Integer flowId, @Param("formId") Integer formId);

    public FlowTypeModel sflowType(Integer runId);

      int updateFlowTypeModel(FlowTypeModel flowTypeModel);

    /**
     * 创建作者:   张航宁
     * 创建日期:   2017/7/18
     * 方法介绍:   根据菜单的父类id查询流程信息
     *
     * @return
     */
    public List<FlowTypeModel> getDataBySortParent(@Param(value = "sortParent") Integer sortParent);

    List<FlowTypeModel> selectFlowAuthOrSearchByCodeId(Map<String, Object> param);

    List<FlowDetailInfo> selectDocumentFloeType();

    int deleteByFlowId(Integer flowId);

//    int deleteByPrimaryKey(Integer flowId);

//    int insert(FlowTypeModelWithBLOBs record);
//
//    int insertSelective(FlowTypeModelWithBLOBs record);
//
//    FlowTypeModelWithBLOBs selectByPrimaryKey(Integer flowId);
//
//    int updateByPrimaryKeySelective(FlowTypeModelWithBLOBs record);
//
//    int updateByPrimaryKeyWithBLOBs(FlowTypeModelWithBLOBs record);
//
//    int updateByPrimaryKey(FlowTypeModel record);

    List<FlowTypeModel> selByFlowSort(Integer flowSort);

    List<FlowTypeModel> selAllType();

    List<FlowTypeModel> selectByFlowType(Integer sortId);

    List<FlowTypeModel> selFlowSorByAndroid( Map<String, Object> param);

    List<FlowTypeModel> selFlowSorByAndroidAdmin( Map<String, Object> param);

    String getFlowName(Integer id);


    FlowTypeModel getFlowByName(@Param("flowName")String flowName);

    List<FlowTypeModel> selectFlowAuthOrSearchCommonWork(Map<String, Object> param);

    List<FlowTypeModel> selectFlowAuthOrSearchCommonWorkAdmin(Map<String, Object> param);

    FlowDetailInfo getAttachment(@Param("flowId")Integer flowId);
    //根据权限查公文流程
    List<FlowTypeModel> sortCommonDocument(Map<String, Object> param);
    //查询流程设计中的查询配置
    FlowTypeModel flowTypequeryList(@Param("flowId")Integer flowId);
    //设置流程设计中的查询配置
    int updateQueryList(FlowTypeModel flowTypeModel);

    //根据flowID串查询flowName串
    String getFlowNames(@Param("ids") String ids);

    //根据flowId串查询flowRun集合
    List<FlowDetailInfo> getFlowTypeModelList(@Param("ids") String ids,@Param("flowName")String flowName,@Param("flowSotr")String flowSotr);

    @Select({"<script> SELECT\n" +
            "\t1 \n" +
            "FROM\n" +
            "\tflow_process \n" +
            "WHERE\n" +
            "\tflow_process.PRCS_ID = 1 \n" +
            "\tAND flow_process.FLOW_ID = #{flowId}\n" +
            "    AND (\n" +
            "    <trim suffixOverrides=\"OR\">\n" +
            "      (\n" +
            "      flow_process.PRCS_USER LIKE concat(\"%,\",#{user},\",%\") OR\n" +
            "      flow_process.PRCS_USER LIKE concat(#{user},\",%\")\n" +
            "      )\n" +
            "      OR\n" +
            "      (\n" +
            "      flow_process.PRCS_DEPT LIKE concat(\"%,\",#{deptId},\",%\") OR\n" +
            "      flow_process.PRCS_DEPT LIKE concat(#{deptId},\",%\")\n" +
            "      )\n" +
            "      OR\n" +
            "      (\n" +
            "      flow_process.PRCS_PRIV LIKE concat(\"%,\",#{privId},\",%\") OR\n" +
            "      flow_process.PRCS_PRIV LIKE concat(#{privId},\",%\")\n" +
            "      )\n" +
            "      OR flow_process.PRCS_DEPT='ALL_DEPT' OR\n" +
            "      <if test=\"privIds!=null\">\n" +
            "        <foreach item=\"item\" collection=\"privIds\">\n" +
            "          (\n" +
            "          flow_process.PRCS_PRIV LIKE concat(\"%,\",#{item},\",%\") OR\n" +
            "          flow_process.PRCS_PRIV LIKE concat(#{item},\",%\")\n" +
            "          )\n" +
            "          OR\n" +
            "        </foreach>\n" +
            "      </if>\n" +
            "      <if test=\"deptIds!=null\">\n" +
            "        <foreach item=\"item\" collection=\"deptIds\">\n" +
            "          (\n" +
            "          flow_process.PRCS_DEPT LIKE concat(\"%,\",#{item},\",%\") OR\n" +
            "          flow_process.PRCS_DEPT LIKE concat(#{item},\",%\")\n" +
            "          )\n" +
            "          OR\n" +
            "        </foreach>\n" +
            "      </if>\n" +
            "    </trim>) </script>"})
    String checkWFNewPriv(Map<String, Object> map);

    //根据flow_id串获取流程
    List<FlowTypeModel> getFlowByFlowIds(Map<String, Object> param);
}